
Lê dados fonte (~705k linhas)
| data/df_all.rds |
705527 |
33 |
| 2014 |
06 |
Segurança Pública |
27420994 |
27420994 |
27420994 |
| 2014 |
08 |
Assistência Social |
80000 |
0 |
0 |
| 2014 |
04 |
Administração |
0 |
0 |
0 |
| 2014 |
23 |
Comércio e Serviços |
1428294 |
1428294 |
1428294 |
| 2014 |
20 |
Agricultura |
12674 |
12674 |
12674 |
Top 5 funções por valor empenhado
|
rank
|
func_cod
|
func
|
n
|
empenhado_b
|
pago_b
|
|
1
|
09
|
Previdência Social
|
11506
|
7478
|
6988
|
|
2
|
06
|
Segurança Pública
|
77487
|
3991
|
3365
|
|
3
|
28
|
Encargos Especiais
|
15356
|
3696
|
3600
|
|
4
|
12
|
Educação
|
235933
|
2520
|
2181
|
|
5
|
10
|
Saúde
|
78066
|
1645
|
1127
|
Compara: empenhado x liquidado x pago
df_all_clean %>%
mutate(func=func%>%fct_reorder(-empenhado,sum)) %>%
filter(as.integer(func)<6) %>%
mutate(func=func%>%fct_drop%>%fct_rev) %>% # for coord_flip
group_by(func) %>%
# milhoes
summarize_at(vars(empenhado,liquidado,pago),
list(~(sum(.)/10^9))) %>%
gather("tipo","valor",-func) %>%
mutate(tipo=factor(tipo,levels=c("pago","liquidado","empenhado"))) %>%
ggplot(aes(func,valor,group=tipo,fill=tipo)) +
geom_col(position="dodge") +
coord_flip() +
labs(title="Valores Totais por Função",
subtitle="Top 5 por empenho total 2014-8",
y="Valor (R$ bilhões)") +
theme(legend.position = "top",
legend.title = element_blank(),
axis.title.y=element_blank())

Facetas: valores por ano
df_all_clean %>%
mutate(func=func%>%fct_reorder(-empenhado,sum)) %>%
filter(as.integer(func)<6) %>%
mutate(func=func%>%fct_drop%>%fct_rev) %>% # for coord_flip
group_by(ano,func) %>%
# milhoes
summarize_at(vars(empenhado,liquidado,pago),
list(~(sum(.)/10^9))) %>%
gather("tipo","valor",-func,-ano) %>%
mutate(tipo=factor(tipo,levels=c("pago","liquidado","empenhado"))) %>%
ggplot(aes(func,valor,group=tipo,fill=tipo)) +
geom_col(position="dodge") +
coord_flip() +
labs(title="Valores Totais por Função",
subtitle="Top 5 por empenho total 2014-8",
y="Valor (R$ bilhões)") +
theme(legend.position = "top",
legend.title = element_blank(),
axis.title.y=element_blank()) +
facet_wrap(~ano)

Interativo: Empenhado vs Pago
abbrev_func <- function(s_vec) s_vec %>% str_split(" ") %>% map_chr(~.x%>%str_sub(end=3)%>%str_c(collapse="."))
anos <- df_all_clean_gathered$ano%>%as.character%>%unique
p <- df_all_clean_gathered %>%
mutate(tipo=tipo%>%fct_recode(emp="empenhado",pag="pago"),
func=func%>%abbrev_func%>%fct_inorder,
valor=(valor/10^9)%>%round(1),
func_tipo=func%>%str_c("_",tipo)%>%fct_inorder) %>%
ggplot(aes(ano,valor,
group=func_tipo,
color=func,linetype=tipo)) +
scale_linetype_manual(values=c("dotted","solid"))+
geom_line(size=I(1.2)) +
labs(title="Valor Anual por Função",
subtitle=sprintf("Anos %s-%s, Top 5",
min(anos),max(anos)),
y = "Valor Total (R$ bilhões)") +
theme_minimal() +
theme(legend.position = "bottom",
legend.title=element_blank(),
axis.title.x=element_blank())
ggplotly(p,tooltip=c("func","valor","tipo")) %>%
# hide_legend() %>%
config(displayModeBar = F)%>%
layout(legend = list(orientation="v",font = list(size = 8)))